import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
// @ts-ignore
import AutoImport from 'unplugin-auto-import/vite'
// @ts-ignore
import Components from 'unplugin-vue-components/vite'
// @ts-ignore
import vueJsx from "@vitejs/plugin-vue-jsx";

// @ts-ignore
import path from 'path'

import {createSvgIconsPlugin} from 'vite-plugin-svg-icons'

import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'
// @ts-ignore
export default defineConfig(({mode}) => {
    // 获取各种环境下对应的变量 mode 那个环境的文件,process.cwd() 环境文件所在的位置
    // @ts-ignore
    const env = loadEnv(mode, process.cwd())
    return {
        plugins: [
            vue(),
            createSvgIconsPlugin({
                iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
                symbolId: 'icon-[dir]-[name]',
            }),
            // * vite 可以使用 jsx/tsx 语法
            vueJsx({
                // 可配置
            }),
            AutoImport({
                resolvers: [ElementPlusResolver()],
            }),
            Components({
                resolvers: [ElementPlusResolver()],
            }),
        ],
        "include": [
            "src/**/*.ts",
            "src/**/*.tsx",
            "src/**/*.vue",
            "tests/**/*.ts",
            "tests/**/*.tsx"
        ],
        compilerOptions: {
            // ...
            "types": ["element-plus/global"]
        },
        resolve: {
            alias: {
                "@": path.resolve("./src") // 相对路径别名配置，使用 @ 代替 src
            }
        },
        server: {
            // headers: {
            //     'Cross-Origin-Opener-Policy': 'same-origin',
            //     'Cross-Origin-Embedder-Policy': 'require-corp'
            // },
            // https://gitee.com/weifuqiang007/erweihuo-front.git
            host: '0.0.0.0', // 修改: 添加 host 配置
            proxy: {
                '/api': {
                    target: "http://192.168.0.47:5001",//目标地址
                    // target:"http://192.168.0.103:5001",//目标地址
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/api/, ''),
                },
            },
        },
    }
})